// pages/member/rankingListSecond/rankingListSecond.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    language: '',
    mailLanguage: '',
    mailSingleReturnName: '',
    mailReturnDetail: '',
    mailReturnAmount: '',
    order_amount: 0.00,
    return_amount: 0.00,
    status_name: '',
    each_return_rate: 0,
    return_mode: '',
    not_return: 0.00,
    id: '',
    order_sn: '',
    created_at: '',
    finish_time: '',

    order_amount_name: '',
    plu_option: {
      'single_return_list_info': {
        url: 'plugin.single-return.api.single-return.get-single-return-queue-detail',
        order_amount_name: '订单金额'
      },
      'consumptionGiftDetail': {
        url: 'plugin.consumption-gift.frontend.controllers.center.get-single-return-queue-detail',
        order_amount_name: '结算金额'
      }
    }
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    this.plu = options.plu ? options.plu : 'single_return_list_info';
    this.initMailLanguage();
    this.getData();
  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {
    // let language = wx.getStorageSync('langIndex');
    // this.setData({ 'language': language.en});
  },

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function() {},

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function() {},

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function() {},

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function() {},

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function() {},

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {},
  initMailLanguage() {
    let mailLanguage;
    let mailReturnDetail = '消费详情';
    let mailReturnAmount = '已赠送数量';
    let mailSingleReturnName = '消费队列';
    if(this.plu == 'single_return_list_info'){
      mailLanguage = wx.getStorageSync('yz_basic_info').lang;
      mailReturnDetail = app.setMailLanguage('消费赠送', mailLanguage?.single_return?.return_detail);
      mailReturnAmount = app.setMailLanguage('已赠送金额', mailLanguage?.single_return?.return_amount);
      mailSingleReturnName = app.setMailLanguage('消费队列', mailLanguage?.single_return?.return_name);
    }
    
    this.setData({
      mailReturnDetail,
      mailReturnAmount,
      mailSingleReturnName,
      order_amount_name: this.data.plu_option[this.plu].order_amount_name
    });
  },

  // 获取数据
  getData() {
    let urlStr = app.getNetAddresss(this.data.plu_option[this.plu].url);
    urlStr += '&queue_id=' + this.options.id;
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resData = res.data;
        if (resData.result === 1) {
          this.setData({
            order_amount: resData.data.order_amount,
            return_amount: resData.data.return_amount,
            status_name: resData.data.status_name,
            each_return_rate: resData.data.each_return_rate,
            return_mode: resData.data.return_mode,
            not_return: resData.data.not_return,
            id: resData.data.id,
            order_sn: resData.data.order_sn,
            created_at: resData.data.created_at,
            finish_time: resData.data.finish_time
          });
        } else {
          wx.showToast({
            title: resData.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },

  goBack() {
    wx.navigateBack({
      delta: 1
    });
  }
});
